# -*- coding: utf-8 -*-
# @Author : kaiquan
# @Time   : 2025/8/21
# @File   : get_adb_devices.py
# @Software: PyCharm
import subprocess
import re

def run_command(command):
    result = subprocess.run(command, shell=True, stdout=subprocess.PIPE)
    try:
        text = result.stdout.decode('utf-8')
        return text
    except UnicodeDecodeError:
        text = result.stdout.decode('utf-8', errors='ignore')
        return text


def get_device_list():
    devices_info = run_command("adb devices")
    device_list = devices_info.split("\n")
    devices = []
    for device in device_list:
        if "device" in device:
            device_id = re.search("(\w+)\tdevice", device)
            if device_id:
                devices.append(device_id.group(1))
    return devices
if __name__ == "__main__":
    device_list = get_device_list()
    print(device_list)